package dlwntk6545;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class J03_MemberService implements J03_IMemberService{
	
	//회원 가입/조회/수정/삭제 처리를 위한 MemberDAO 객체를 미리 생성
	private J03_MemberDAO mdao = new J03_MemberDAO();
	
	@Override
	public void createMember() {
		System.out.println("1.회원가입");
		
		J03_MemberVO m = new J03_MemberVO();
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("아이디를 입력하세요");
		m.setUserid(sc.next());
		
		System.out.println("비밀번호를 입력하세요");
		m.setPasswd(sc.next());
		
		System.out.println("이름을 입력하세요");
		m.setName(sc.next());
		
		System.out.println("이메일을 입력하세요");
		m.setEmail(sc.next());
		
		//입력받은 데이터들을 member 테이블에 저장
		
		if(mdao.insertMember(m))
			System.out.println("회원가입 성공");
		else
			System.out.println("회원가입 실패");
	}

	@Override
	public void readMember() {
		
		//select 문을 이용해서 member 테이블의 모든 레코드를 가져와서 콘솔에 출력
		for(J03_MemberVO m : mdao.selectMember()) {
			
			//콘솔에 출력
			System.out.print(m.getMno());
			System.out.print("/");
			System.out.print(m.getUserid());
			System.out.print("/");
			System.out.print(m.getPasswd());
			System.out.print("/");
			System.out.print(m.getName());
			System.out.print("/");
			System.out.print(m.getEmail());
			System.out.print("/");
			System.out.print(m.getRegdate());
			System.out.println();
			
			
			List<J03_MemberVO> results = new ArrayList<J03_MemberVO>();
			
			
			for(int i = 0; i <results.size(); ++i){
				
				J03_MemberVO v = results.get(i);
				System.out.println(v.getMno());
				
			}
			
		}
		
	}

	@Override
	public void modifyMember() {
		
		readMember();
		J03_MemberVO mvo = new J03_MemberVO();
		Scanner sc = new Scanner(System.in);
		
		System.out.println("새로운 회원번호를 입력하세요");
			mvo.setMno(sc.next());
		System.out.println("새로운 비밀번호를 입력하세요");
			mvo.setPasswd(sc.next());
		System.out.println("새로운 이름를 입력하세요");
			mvo.setName(sc.next());
		System.out.println("새로운 이메일를 입력하세요");
			mvo.setEmail(sc.next());
		if(mdao.updateMember(mvo))
			System.out.println("회원정보수정 성공");
		else System.out.println("회원정보수정 실패 꺼졍");
	}

	@Override
	public void removeMember() {
		
		readMember();		//전체 회원출력
		J03_MemberVO mvo = new J03_MemberVO();
		Scanner sc = new Scanner(System.in);
		
		System.out.println("삭제할 회원의 번호를 입력하세요");
			mvo.setMno(sc.next());
			if(mdao.deleteMember(mvo))
				System.out.println("회원 삭제 성공");
			else
				System.out.println("회원 삭제 실패");
		
	}
	
	
	
}
